<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/10/16 15:43
 * Desc: 导游
 */
class Controller_Pc_Api_V2_Guide extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Guide
     */
    private $validation;

    /**
     * 服务
     * @var Service_Api_Guide
     */
    private $service;

    public function before()
    {
        parent::before();

        // 验证
        $this->validation = Request_Api_V2_Factory::create('guide', $this->request_params);

        // 服务
        $this->service = new Service_Api_Guide();

        // 返回数据
        $this->result = array('status' => true, 'msg' => '操作成功', 'data' => array());
    }

    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    // 获取推荐
    public function action_recommend()
    {
        try {
            $this->validation->recommend()->check();

            $this->result['data'] = $this->service->recommend($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 查询条件
    public function action_query_condition()
    {
        try {
            $this->result['data'] = $this->service->query_condition();
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 查询服务列表
    public function action_query()
    {
        try {
            $this->validation->query()->check();

            $this->result['data'] = $this->service->search($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 导游所能提供服务
    public function action_get_guide_service()
    {
        try {
            $this->validation->get_guide_service()->check();

            $this->result['data'] = $this->service->get_guide_service($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 服务详情
    public function action_get_service_info()
    {
        try {
            $this->validation->get_service_info()->check();

            $this->result['data'] = $this->service->get_service_info($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 导游信息
    public function action_info()
    {
        try {
            $this->validation->info()->check();

            $this->result['data'] = $this->service->info($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 日历报价
    public function action_calendar()
    {
        try {
            $this->validation->calendar()->check();

            $this->result['data'] = $this->service->calendar($this->request_params['service_id']);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 添加订单
    public function action_add_order()
    {
        try {
            $this->validation->add_order()->check();

            $this->request_params['member_info'] = $this->member_info;
            $this->result['data']                = $this->service->create_order($this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }

}